package com.mrtan.controller;

import cn.dev33.satoken.util.SaResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mrtan.bean.Account;
import com.mrtan.bean.OrderSell;
import com.mrtan.dto.PageBeanDto;
import com.mrtan.service.AccountService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/account")
public class AccountController {
    @Resource
    private AccountService accountService;

    @GetMapping("/allAccounts")
    public SaResult selectAllAccounts(@RequestParam(defaultValue = "1") int page,
                                      @RequestParam(defaultValue = "10") int limit) {
        PageHelper.startPage(page, limit);
        List<Account> accounts = accountService.selectAllAccounts();
        PageInfo<Account> pageInfo = new PageInfo<>(accounts);
        PageBeanDto<Account> pageBeanDto = new PageBeanDto();
        pageBeanDto.setList(pageInfo.getList());
        pageBeanDto.setTotal((int) pageInfo.getTotal());
        return SaResult.ok()
                .setData(pageBeanDto);
    }
}
